﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using EZCRS.HCMS.Bll;
using EZCRS.HCMS.Bll.baseinfo;
using EZCRS.HCMS.Web;
using EZCRS.HCMS.Entity;
using System.Collections.Generic;

namespace EZCRS.HCMS.Web.manage.AIR
{
    public partial class air_log : ManageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.BasHotelId == 0)
                Response.Write(CFun.AlertMeg(Resources.Site.MustHotel, "back", ""));

            if (!Page.IsPostBack)
            {
                //Titlepage1.initlabnew = "<a href=\"salepolicy_add.aspx\"><img src=\"../../image/new.gif\" border=\"0\"></a> ";

                //RadioButtonList1.Items.Add(new ListItem("aa","bb"));

                //BindData();

                //CheckModule(70);

                if (Request.QueryString["action"] != null)
                {
                    //get data
                    if (Request.QueryString["action"].ToLower() == "get")
                    {
                        int iPageIndex = 1;
                        int iPageSize = 15;
                        int iState = 1;

                        if (!string.IsNullOrEmpty(Request.Params["page"]))
                            int.TryParse(Request.Params["page"], out iPageIndex);

                        if (!string.IsNullOrEmpty(Request.Params["rp"]))
                            int.TryParse(Request.Params["rp"], out iPageSize);

                        if (!string.IsNullOrEmpty(Request.Params["query"]))
                            int.TryParse(Request.Params["query"], out iState);


                        Response.Write(GetJSON(iPageIndex, iState, iPageSize));
                        Response.End();
                    }
                    else if (Request.QueryString["action"].ToLower() == "apply")
                    {
                        //int iID = 0;

                        //if (!string.IsNullOrEmpty(Request.Params["id"]))
                        //    int.TryParse(Request.Params["id"], out iID);

                        //bool b = Do(iID);

                        //if (b)
                        //    Response.Write("{state:1}");
                        //else
                        //    Response.Write("{state:0}");

                        //Response.End();
                    }
                }
            }
        }

        /// <summary>
        /// 显示CODE列表
        /// </summary>
        private string GetJSON(int PageIndex, int State, int PageSize)
        {

            EZCRS.HCMS.Bll.AIR.AIR air = new EZCRS.HCMS.Bll.AIR.AIR();

            int iPageCount = 0;
            int iRecordCount = 0;

            List<AIR_Log> lst = air.GetAirLogPID(base.BasPropertyId, PageIndex, PageSize, "", out iRecordCount, out iPageCount);

            string strJson = "{\"total\":" + iRecordCount + ",\"page\":" + PageIndex.ToString() + ",\"rows\":[";

            foreach (AIR_Log plan in lst)
            {
                strJson += "{\"id\":" + plan.ID.ToString() + ",";
                strJson += "\"cell\":[";

                strJson += "\"" + plan.ID.ToString() + "\","; //id
                strJson += "\"" + plan.PlanLevel + "\",";
                strJson += "\"" + plan.State + "\",";

                strJson += "\"" + plan.StartDate.ToString("yyyy-MM-dd") + "\",";
                strJson += "\"" + plan.EndDate.ToString("yyyy-MM-dd") + "\",";

                strJson += "\"" + plan.Operator + "\",";
                strJson += "\"" + plan.CrateDate.ToString() + "\"";

                strJson += "]},";
            }

            strJson = strJson.Replace("\r\n", " ");
            strJson = strJson.TrimEnd(',');
            strJson += "]}";

            return strJson;
        }
    }
}
